package com.info3k.client.commands.address;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.info3k.client.Info3K;
import com.info3k.client.components.MyAddressList;

public class MyAddressCommand implements Command {
	
	private NewAddressCommand newAddressCommand;
	
	private Info3K info3k;
	
	private Button addAddress = new Button(Info3K.msgs.new1() + " "+ Info3K.msgs.address(), new ClickHandler(){
		public void onClick(ClickEvent event) {
			newAddressCommand = new NewAddressCommand(info3k);
			newAddressCommand.execute();
		}
	});
	
	private RootPanel parent;
	
	public MyAddressCommand(RootPanel p, Info3K info){
		this.info3k = info;
		this.parent = p;
	}
	
	public void execute() {
		parent.clear();
	
		final VerticalPanel verPanel = new VerticalPanel();
		
		if(info3k.getLoginManager().getUser()!=null) verPanel.add(addAddress);
		verPanel.setWidth("100%");
		parent.add(verPanel);
		
		MyAddressList addressList = new MyAddressList(info3k.getLoginManager().getUser(), info3k);
		addressList.setWidth("100%");
		verPanel.add(new HTML("<div class=\"h_line\"></div>"));
		
		verPanel.add(addressList);
	}
}
